package com.zisu.wcsopcua.taskPool;


import com.zisu.wcsopcua.dispatch.constant.QGSConstant;
import com.zisu.wcsopcua.enums.ddj.Plc2WcsVarEnum;
import com.zisu.wcsopcua.enums.ddj.Wcs2PlcVarEnum;
import com.zisu.wcsopcua.opcua.selfunion.UAService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.Callable;

/**
 * @Author: 蔡翔
 * @Date: 2019/10/30 16:23
 * @Version 1.0
 */
public class HealthCheckRunnable<T> implements Callable<T> {
    private final static Logger logger = LoggerFactory.getLogger(HealthCheckRunnable.class);
    private UAService uaService;


    public HealthCheckRunnable(UAService uaService){
        this.uaService = uaService;

    }
    public HealthCheckRunnable(){

    }
    @Override
    public T call() throws Exception {
        Integer res = 1;
        while (true){
            Boolean heart01 = Boolean.valueOf(getValue(Plc2WcsVarEnum.Heart));
            if(heart01){
                Boolean heart02 = setValue(Wcs2PlcVarEnum.Heart, true);
                if(heart02){
                    //sendTo success
                }
            }else {
                //sendTo fail
            }

            Thread.sleep(100);
        }
        //return (T(1));
    }
    private String getValue(Plc2WcsVarEnum var) throws Exception {
        return uaService.getValue(var.getNamespace(), var.getIdentity(), QGSConstant.plcName).getValue().getValue().toString();
    }
    private Boolean setValue(Wcs2PlcVarEnum var, Object newValue) throws Exception {
        return uaService.setValue(var.getNamespace(), var.getIdentity(),newValue, QGSConstant.plcName);
    }

}
